package com.jp.knowledge.logic;

import android.app.Activity;
import android.content.Context;

import com.jiayen.util.ToasUtil;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.utils.Log;
import com.umeng.socialize.utils.ShareBoardlistener;

/**
 * Created by jiayen on 16/12/2.
 *
 * 分享逻辑
 */

public class ShareLogic {


    private ShareBoardlistener callBack;
    private Context mContext;


    public ShareLogic(Context context ,ShareBoardlistener callBack){
        this.mContext=context;
        this.callBack=callBack;
    }

    /**
     * 分享
     */
    public void share() {
        new ShareAction((Activity) mContext).setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE, SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE)
                .addButton("share_copy_url", "share_copy_url", "ttoutiaofuzhilianjie", "ttoutiaofuzhilianjie")
                .setShareboardclickCallback(callBack).open();
    }

    public UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onResult(SHARE_MEDIA platform) {
            Log.d("plat", "platform" + platform);
            if (platform.name().equals("WEIXIN_FAVORITE")) {
                ToasUtil.toast(mContext, platform + " 收藏成功啦");
            } else {
                ToasUtil.toast(mContext, platform + " 分享成功啦");
            }
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            ToasUtil.toast(mContext, platform + " 分享失败啦");
            if (t != null) {
                Log.d("throw", "throw:" + t.getMessage());
            }
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            ToasUtil.toast(mContext, platform + " 分享取消了");
        }
    };



}
